<?php
/* 
	[BuyPg] (C) 2010-2011 Buypg
	$Id: IndexAction.class.php 2011-3-30 14:01:53 wufujun $
 */

if (!defined('THINK_PATH')){
	exit('Access Denied');
}

class IndexAction extends BpAction{
	public function  index(){
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		//网站系统相关设置在当前控制器私有设置
		$pgsys['sys_set']['set_footer_tools'] = 1; //网站页脚 ”常用工具“ 显示
		//定义左侧分类
		$LeftCate = getLeftCategory();
		//定义右侧专题列表
		$RightZT = getRightZT();
		//推荐site
		$DbCommendStie = D("NbSite");
		$CommendSite = $DbCommendStie->getCommendSite('flag = 1 and country_id = 0 and commend = 1' , 'f7 desc' , 35);
		//新闻
		$DbNews = D("News");
		$NewsList = $DbNews->getNewsList('' , 'news_id desc' , 22);

		//优惠分类
		$YouHuiClass = $RecommendYouHuiInClass = getYouHuiClass();
		//分类下的推荐优惠
		$YouHuiModel = M("Youhui");
		foreach($RecommendYouHuiInClass as $key => $value){
			$RecommendYouHui = $YouHuiModel->where("cid = '{$value['id']}' and status=1 and recommend = 1")->limit(6)->order('dateline DESC')->select();
			foreach($RecommendYouHui as $k => $v){
				$RecommendYouHui[$k]['image_b'] = __ROOT__."/attachment/".$v['img'];
				$RecommendYouHui[$k]['image_m'] = __ROOT__."/attachment/".$v['img'].".m.jpg";
				$RecommendYouHui[$k]['image_s'] = __ROOT__."/attachment/".$v['img'].".s.jpg";
			}
			$RecommendYouHuiInClass[$key]['RecommendYouHui'] = $RecommendYouHui;
		}
		//购物攻略
		$ShoppingNewsModel = M("ShoppingNews");
		$ShoppingNewsList = $ShoppingNewsModel->where("status = 1")->limit(8)->order('dateline DESC')->select();
		//收录商家
		$IndexSite = getIndexSite();
		//模板输出
		$this->assign('sys_set' , $pgsys['sys_set']); //网站系统相关设置当前私有设置模板输出
		$this->assign('leftcate' , $LeftCate);
		$this->assign('rightzt' , $RightZT);
		$this->assign('commendsite' , $CommendSite);
		$this->assign('newslist' , $NewsList);
		$this->assign('YouHuiClass' , $YouHuiClass);
		$this->assign('RecommendYouHuiInClass',$RecommendYouHuiInClass);
		$this->assign('ShoppingNewsList',$ShoppingNewsList);
		$this->assign('IndexSite' , $IndexSite);
		$this->display('buypg@Index:index');
	}

	public function zhuzhuangtu(){
		C ( 'SHOW_PAGE_TRACE', false ); //关闭调试信息
		$p = isset($_GET['p'] )? intval($_GET['p'])  : 1 ;
		$inajax = $_GET['inajax'] ? intval($_GET['inajax']) : 0;
		//判断是否是ajax操作，如果是则加入ajax参数以后ajax操作，如果不是则以正常页显示
		if ($inajax){
			$onclick = "onclick=ajax_page(event,this.id,'#website1') return false;";
		}
		//获取site
		$DbSite = D("NbSite");
		$resultSite = $DbSite->getLimitSite('homepage = 1 and flag = 1' , '' , ($p-1).',1');
		if(!$resultSite){
			$this->error('您访问的信息不存在或已经被删除');
		}
		
		//获取alexa
		$arrAlexa = array();
		$arrAlexa = GetAlexa(urldecode($resultSite[0]['site_link']),$resultSite[0]['site_id']);
		
		//获取回头率
		$DbSiteHt = M("SiteHt");
		$DbNbHt = M("NbHt");
		
		$arrSiteHt = $DbSiteHt->where("site_id = ".$resultSite[0]['site_id'])->find();
		if($arrSiteHt){
			$Htl = round($arrSiteHt['ht1'] / ($arrSiteHt['ht1'] + $arrSiteHt['ht2']),2) * 100; 
		}else{
			if(S('Htl_'.$resultSite[0]['site_id'])){
				$Htl = S('Htl_'.$resultSite[0]['site_id']);
			}else{
				$Ht1 = $DbNbHt->where("site_id = ".$resultSite[0]['site_id']." and ht = 1")->count();
				$HtSum = $DbNbHt->where("site_id = ".$resultSite[0]['site_id'])->count();
				$Htl = round(($Ht1 / $HtSum) , 2) * 100 ;
				S('Htl_'.$resultSite[0]['site_id'] , $Htl , 3600);
			}
		}
		
		//分页设置
		$page = "<a id='zhuzhuang_p_bf' ".$onclick." href='".U("BuyPg://".MODULE_NAME."/".ACTION_NAME."?p=1")."' class='fenyeimg_l' ></a>";
		for ($i = 1; $i < 7; $i++){
			if($p == $i){
				$page .= "<a>" . $i . "&nbsp;</a> ";
			}else{
				$page .= "<a id='zhuzhuang_pg_".$i."' ".$onclick." href='".U("BuyPg://".MODULE_NAME."/".ACTION_NAME."?p=$i")."' >" . $i . "&nbsp;</a> ";
			}
		}
		$page.="<a id='zhuzhuang_p_nx' ".$onclick." href='".U("BuyPg://".MODULE_NAME."/".ACTION_NAME."?p=6")."'  class='fenyeimg_r' ></a>";
		//模块输出
		$this->assign('resultsite' , $resultSite[0]); //当前只取一条数据，为了方便使用，把二维数据重新定义为一维数组
		$this->assign('arrAlexa' , $arrAlexa);
		$this->assign('Htl' , $Htl);
		$this->assign('page' , $page);
		$this->display('zhuzhuangtu');
	}

	public  function test(){
		import("@.ORG.Editor");
		import("@.ORG.Input");
		$str = "<span onclick='124' style='background:#fff url(12345);FONT-SIZE:14px;'  >测试一下</span><script>alert('12345')</script>";
		$str = Input::safeHtml($str);
		echo $str;
		$ke = new Editor();
		$ke->littleToolType = true;
		$KindEditor = $ke->show();
		$this->assign('KindEditor' , $KindEditor);
		$this->display(APP_TP_PATH.'test.html');
	}

	public function Mypage(){
			//普通方式实现分页
			$news = M('News');
			import("@.ORG.Page"); //导入分页类
			$count = $news->count();    //计算总数
			$p = new Page ( $count, 5 );
			$list=$news->limit($p->firstRow.','.$p->listRows)->order('news_id desc')->findAll();
			$page = $p->show ();
			$this->assign ( "page", $page );
			$this->assign ( "list", $list );
			$this->display(APP_TP_PATH.'test');
	}

}
?>
